package org.achievement.system.common;

public class RequestResult<T> {

    /**
     * 成功为0，其他为报错
     */
    private int code;
    private String msg;
    private T data;

    public static <T> RequestResult<T> success(T data) {
        RequestResult result  = new RequestResult<>();
        result.setMsg("成功！");
        result.setData(data);
        return result;
    }

    public static  RequestResult success(String msg) {
        RequestResult result  = new RequestResult<>();
        result.setMsg(msg);
        return result;
    }

    public static <T> RequestResult<T> error(String msg) {
        RequestResult result  = new RequestResult<>();
        result.setCode(500);
        result.setMsg(msg);
        return result;
    }
    public static <T> RequestResult<T> error(int code, String msg) {
        RequestResult result  = new RequestResult<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
